//
// Created by hxp on 24-8-14.
//

template <class T>
void Printf<T>::vector(const std::vector<T>& v) {
    std::cout << "[ ";
    int count = 0;
    for(const auto& e : v) {
        ++count;
        if (count != v.size()) std::cout << e << ", ";
        else std::cout << e << " ";
    }
    std::cout << "]" << std::endl;
}

template <class T>
void Printf<T>::vector2d(const std::vector<std::vector<T>>& v2d) {
    std::cout << "[ " << std::endl;;
    for(const auto& v : v2d) {
        Printf<T>::vector(v);
    }
    std::cout << "]" << std::endl;
}

template <class T>
void Printf<T>::singleList(ListNode<T>* l) {
    std::cout << "{ ";
    ListNode<T>* current = l;
    while (current != nullptr) {
        if (current->next != nullptr) {
            std::cout << current->val << ", ";
        } else {
            std::cout << current->val << " ";
        }
        current = current->next;
    }
    std::cout << "}" << std::endl;
}

template <class T>
void Printf<T>::binaryTree(TreeNode<T>* t) {
    if (!t) return;

    std::queue<TreeNode<T>*> q;
    q.push(t);

    while (!q.empty()) {
        int node_nums = q.size();
        while (node_nums != 0) {
            TreeNode<T>* node = q.front(); q.pop();
            if (node) {
                std::cout << node->val << "\t";
                q.push(node->left);
                q.push(node->right);
            } else {
                std::cout << "*\t";
            }
            --node_nums;
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;
}
